package com.hnkywl.sts.action.organ;

import com.hnkywl.sts.entity.organ.Gc;
import com.hnkywl.sts.service.organ.GcService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created with IntelliJ IDEA.
 * User: jerry
 * Date: 13-3-28
 * Time: 上午10:18
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/organ/gc")
public class GcAction extends SimpleActionSupport {
    private GcService gcService;
    //工程
    private Gc gc;
    //工程名称
    private String mc;
    //企业机构Id
    private Long qyjgId;
    //企业机构名称
    private String qyjgName;
    //传入的id值
    private Long gcId;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows;
    //行索引
    private int index;
    //远程ajax验证的值
    private String validateVal;
    //需要远程ajax验证的属性
    private String validateField;
    //工程的查询分页
    @Action("gcList")
    public void gcList() {
        this.renderJson(this.gcService.findAllGc(mc,qyjgName, page, rows));
    }

    //工程的查询分页
    @Action("gcmcList")
    public void gcmcList() {
        this.renderJson(this.gcService.findAllGcmc(qyjgId));
    }

    @Action("gc_content")
    public String gcContent() {
        if (gcId != null){
            gc = gcService.findGcDetail(gcId);
        }
        return SUCCESS;
    }


    /**
     * 方法名:     addGc
     * 功能描述:      向数据库添加工程
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     * 创建人:     zsp
     * 创建日期:   13-3-28上午11:47
     * 修改人:     zsp
     * 修改日期:   13-3-28上午11:47
     */
    @Action("add_gc")
    public void addGc() {
        try {
            this.gcService.saveGc(gc);
            renderText("{\"statusCode\":\"200\", \"message\":\"添加工程成功！\", \"operationType\":\"add\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    /**
     * 方法名:     updateGc
     * 功能描述:      修改工程
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     * 创建人:     scl
     * 创建日期:   13-3-28上午11:50
     * 修改人:     scl
     * 修改日期:   13-3-28上午11:50
     */
    @Action("update_gc")
    public void updateGc() {
        try {
            this.gcService.updateGc(gc);
            renderText("{\"statusCode\":\"200\",\"message\":\"修改工程成功！\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }

    }

    /**
     * 方法名:     deleteGc
     * 功能描述:      删除数据库工程
     * 输入参数:
     * 异常:      <RuntimeException  Exception>
     * 创建人:     zsp
     * 创建日期:   13-3-28上午11:47
     * 修改人:     zsp
     * 修改日期:   13-3-28上午11:47
     */
    @Action("delete_gc")
    public void deleteGc() {
        try {
            this.gcService.deleteGc(gcId);
            renderText("{\"statusCode\":\"200\", \"message\":\"删除工程成功！\", \"operationType\":\"delete\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    /**
     * 远程ajax验证
     */
    @Action("ajax_validate")
    public void ajaxValidate() {
        if (!gcService.ajaxValidate(gcId,validateVal,validateField))
            renderJson("{\"valid\":true}");
        else
            renderJson("{\"valid\":false}");
    }


    @Action("cxgcList")
    public void cxgcList() {
        this.renderJson(this.gcService.findAllgc());
    }
    @Autowired
    public void setGcService(GcService gcService) {
        this.gcService = gcService;
    }

    public Gc getGc() {
        return gc;
    }

    public void setGc(Gc gc) {
        this.gc = gc;
    }

    public String getMc() {
        return mc;
    }

    public void setMc(String mc) {
        this.mc = mc;
    }

    public Long getGcId() {
        return gcId;
    }

    public void setGcId(Long gcId) {
        this.gcId = gcId;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getValidateVal() {
        return validateVal;
    }

    public void setValidateVal(String validateVal) {
        this.validateVal = validateVal;
    }

    public String getValidateField() {
        return validateField;
    }

    public void setValidateField(String validateField) {
        this.validateField = validateField;
    }

    public Long getQyjgId() {
        return qyjgId;
    }

    public void setQyjgId(Long qyjgId) {
        this.qyjgId = qyjgId;
    }

    public String getQyjgName() {
        return qyjgName;
    }

    public void setQyjgName(String qyjgName) {
        this.qyjgName = qyjgName;
    }
}
